// ==UserScript==
// @name        自动检测提醒
// @namespace   Violentmonkey Scripts
// @match       https://pancakeswap.finance/swap
// @grant       none
// @version     1.0
// @author      -
// @description 2022/8/8 22:26:04
// @require     https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js
// ==/UserScript==


var synth = window.speechSynthesis
var u = new SpeechSynthesisUtterance();
//汉语
u.lang = 'zh-CN';
u.rate = 1;


function speak(textToSpeak) {
    u.text = textToSpeak;
    synth.speak(u)
}

function Refresh(){
  var isSale = false

  $('#__next > div:eq(0) > div:eq(2) > div > div:eq(0) > div:eq(0) > div > div > div > div:eq(0) > div > div:eq(0) > div:eq(0) > div:eq(1) > button:nth-child(3)').click();
  var isChecked = $('#check_isopen').is(":checked")
  
  if(isChecked){
  
    var isUSDT = $('#pair').text() == 'USDT'
    if(isUSDT){

      var USDT = $('#swap-currency-input > div:eq(1) > label > div:eq(0) > input').val();

      // 买入
      if(USDT < 185 && USDT != ''){
        $('#swap-button').click()
        speak('开始兑换')
        isSale = true
        
      }

    }else{
      var USDT = $('#swap-currency-output > div:eq(1) > label > div:eq(0) > input').val();

      // 卖出
      if(USDT > 210 && USDT != ''){
        $('#swap-button').click()
        speak('开始兑换')
        isSale = true
        
      }
    }
  }
  
  if(!isSale){
    setTimeout(Refresh, 2000);
  }
  
}

function addcheckbox(){
  $('#__next>div:eq(0)>div:eq(2)>div>div:eq(0)>div:eq(0)>div>div>div>div>div>div:eq(0)>div:eq(0)>div:eq(1)').append("<input id='check_isopen' type='checkbox' value='' name='header'/>");
}

$(function(){

  setTimeout(Refresh, 2000);
  
  setTimeout(addcheckbox, 3000);

})
